package com.flyiu.data.consistency.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Lob;
import javax.persistence.Table;

import com.flyiu.foundational.util.ZipUtils;

/**
 * @author 作者 E-mail:
 * @version 创建时间：2017年10月27日 下午5:39:21 类说明
 */
@Entity
@Table(indexes = { @Index(name = "IDX_IDEM_ENTITY", columnList = "idemValue", unique = true), })
public class IdempotentEntity {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int    id;

    /**
     * 对象hash值-用以验证对象被窜改
     */
    private String hash;

    /**
     * 入参
     */
    @Lob
    @Column(columnDefinition="text")
    private String context;

    /**
     * 返回值
     */
    @Lob
    @Column(columnDefinition="text")
    private String response;

    /**
     * 幂等KEY
     */
    private String idemValue;

    /**
     * 状态 初始为I，确认为COMMIT
     */
    private String state = "I";

    /**
     * 幂等性方法名称
     */
    private String name;

    /**
     * 业务ID
     */
    private String bussinessId;
    
    /**
     * 
     */
    private Date createDate;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getHash() {
        return hash;
    }

    public void setHash(String hash) {
        this.hash = hash;
    }

    public String getContext() {
        return context;
    }

    public void setContext(String context) {
        this.context = context;
    }

    public String getResponse() {
        return response;
    }
    

    public String getUnCompressResponse() {
        return ZipUtils.uncompress(response);
    }

    public void setResponse(String response) {
        this.response = response;
    }

    public String getIdemValue() {
        return idemValue;
    }

    public void setIdemValue(String idemValue) {
        this.idemValue = idemValue;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * Getter method for property <tt>bussinessId</tt>.
     * 
     * @return property value of bussinessId
     */
    public String getBussinessId() {
        return bussinessId;
    }

    /**
     * Setter method for property <tt>bussinessId</tt>.
     * 
     * @param bussinessId value to be assigned to property bussinessId
     */
    public void setBussinessId(String bussinessId) {
        this.bussinessId = bussinessId;
    }

    /**
     * Getter method for property <tt>createDate</tt>.
     * 
     * @return property value of createDate
     */
    public Date getCreateDate() {
        return createDate;
    }

    /**
     * Setter method for property <tt>createDate</tt>.
     * 
     * @param createDate value to be assigned to property createDate
     */
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

}
